package com.lcl.jarvis.bo.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lcl.jarvis.entity.TbUserAuthDO;
import com.lcl.jarvis.dto.TbUserAuthDtoAssembler;
import com.lcl.jarvis.dao.TbUserAuthDAO;
import com.lcl.jarvis.bo.TbUserAuthBO;

import com.lcl.jarvis.dto.TbUserAuthQueryDTO;
import com.lcl.jarvis.dto.TbUserAuthDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;


/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author licl
 * @since 2024-05-16
 */
@Service
@Slf4j
public class TbUserAuthBOImpl implements TbUserAuthBO {

    private final TbUserAuthDAO tbUserAuthDAO;

    @Autowired
    public TbUserAuthBOImpl(TbUserAuthDAO tbUserAuthDAO) {
        this.tbUserAuthDAO = tbUserAuthDAO;
    }


    /**
     * 分页查询信息
     *
     * @param tbUserAuthQueryDto 参数 DTO 对象
     * @return 分页对象
     */
    @Override
    public Map<String, Object> queryByDTOPage(TbUserAuthQueryDTO tbUserAuthQueryDto) {

        //调用中台或DB
    	IPage<TbUserAuthDO> page = new Page(tbUserAuthQueryDto.getCurrentPage(), tbUserAuthQueryDto.getPageSize());
    	IPage<TbUserAuthDO> da = tbUserAuthDAO.baseQueryByDTO(page, tbUserAuthQueryDto);
    	List<TbUserAuthDTO> tbUserAuthList = TbUserAuthDtoAssembler.toTbUserAuthDtoList(da.getRecords());

    	Map<String,Object> rs = new HashMap<String, Object>();
    	rs.put("currentPage", da.getCurrent());
    	rs.put("pageSize", da.getSize());
    	rs.put("total", da.getTotal());
    	rs.put("result", tbUserAuthList);
    	return rs;

	}

    /**
     * 分页查询信息
     *
     * @param tbUserAuthDto 参数 DTO 对象
     * @return 分页对象
     */
    @Override
    public List<TbUserAuthDTO> queryByDTO(TbUserAuthQueryDTO tbUserAuthDto) {
        List<TbUserAuthDO> tbUserAuthList = tbUserAuthDAO.baseQueryByDTO(tbUserAuthDto);
        return TbUserAuthDtoAssembler.toTbUserAuthDtoList(tbUserAuthList);
    }

    /**
     * 通过ID查询
     *
     * @param id ID
     * @return TbUserAuth
     */
    @Override
    public TbUserAuthDTO getById(String id) {
        TbUserAuthDO tbUserAuth = tbUserAuthDAO.selectById(id);
        return TbUserAuthDtoAssembler.toTbUserAuthDto(tbUserAuth);
    }

    /**
     * 添加
     *
     * @param tbUserAuthDto TbUserAuthDTO
     * @return TbUserAuthDTO
     */
    @Override
    public TbUserAuthDTO save(TbUserAuthDTO tbUserAuthDto) {
        TbUserAuthDO tbUserAuth = TbUserAuthDtoAssembler.toTbUserAuthDo(tbUserAuthDto);
        tbUserAuth.setCreateTime(new Date());
        tbUserAuthDAO.insert(tbUserAuth);
        return TbUserAuthDtoAssembler.toTbUserAuthDto(tbUserAuth);
    }


    /**
     * 更新
     *
     * @param tbUserAuthDto TbUserAuthDTO
     * @return TbUserAuthDTO
     */
    @Override
    public TbUserAuthDTO updateById(TbUserAuthDTO tbUserAuthDto) {
        TbUserAuthDO tbUserAuth = TbUserAuthDtoAssembler.toTbUserAuthDo(tbUserAuthDto);
        tbUserAuthDAO.updateById(tbUserAuth);
        return TbUserAuthDtoAssembler.toTbUserAuthDto(tbUserAuth);
    }


    /**
     * 物理删除
     *
     * @param id 主键
     */
    @Override
    public void delete(String id) {
        tbUserAuthDAO.deleteById(id);
    }

    @Override
    public TbUserAuthDTO queryUserByUsername(TbUserAuthQueryDTO tbUserAuthDto) {
        TbUserAuthDTO tbUserAuth = tbUserAuthDAO.queryUserByUsername(tbUserAuthDto);
        return tbUserAuth;
    }

}
